package test.h0818;

import java.util.Arrays;
import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int[] nums = Arrays.stream(s.split(",")).mapToInt(Integer::parseInt).toArray();
        int jump = Integer.parseInt(sc.nextLine());
        int surivivors=Integer.parseInt(sc.nextLine());
        System.out.println(getResult(nums, jump, surivivors));
    }

    private static int getResult(int[] nums, int jump, int surivivors) {
        CycleLinkedList list = new CycleLinkedList();
        //初始化
        for (int num : nums) {
            list.add(num);
        }

        Node cur = list.head.next;
        while (list.size>surivivors){
            for (int i = 0; i <=jump; i++) {
                if (i==jump){
                    cur=list.remove(cur);
                }else {
                    cur=cur.next;
                }
            }
        }
        int ans=0;
        while (list.size>0){
            ans+=cur.val;
            cur=cur.next;
        }
        return ans;
    }

    static class Node {
        //头尾节点
        //val
        int val;
        Node prev;
        Node next;

        public Node(int val) {
            this.val = val;
        }
    }

    static class CycleLinkedList {
        private Node head;
        private Node tail;
        private int size;

        public CycleLinkedList() {
            this.size = 0;
            this.head = null;
            this.tail = null;
        }

        //add方法
        public void add(int val) {
            Node node = new Node(val);
            if (head == null) {
                head = node;
                tail = node;
                head.prev = tail;
                head.next = tail;
            } else {
                head.prev = node;
                node.next = head;
                tail.next = node;
                node.prev = tail;
                //新的尾节点
                tail = node;
            }
            this.size++;
        }

        //remove方法
        public Node remove(Node node) {
            Node pr = node.prev;
            Node ne = node.next;

            pr.next=ne;
            ne.prev=pr;

            node.prev=null;
            node.next=null;
            if (head==node){
                this.head=ne;
            }
            if (tail==node){
                this.tail=pr;
            }
            //size改变
            this.size--;
            return ne;
        }

        public int getSize() {
            return size;
        }
    }
}
